package com.xs.ahoi.hcxs.receiver;

import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import com.xs.ahoi.hcxs.handler.NotifyPlayHandler;
import com.xs.ahoi.hcxs.service.BookFactory;
import com.xs.ahoi.hcxs.utils.LogUtil;

/**
 * 接收通知栏事件广播
 */
public class NotificationPlayReceiver extends BroadcastReceiver {

    public static final String ACTION_PREV = "prev";
    public static final String ACTION_NEXT = "next";
    public static final String ACTION_PLAY = "play";
    public static final String ACTION_PAUSE = "justPause";
    public static final String ACTION_CLOSE = "close";

    @Override
    public void onReceive(Context context, Intent intent) {
        String action = intent.getAction();
        LogUtil.e("收到广播，action: " + action);

        // 上一章
        if (ACTION_PREV.equals(action)) {
            BookFactory.getInstance().doPagePrevCatalog();
        }
        // 下一章
        else if (ACTION_NEXT.equals(action)) {
            BookFactory.getInstance().doPageNextCatalog();
        }
        // 播放
        else if (ACTION_PLAY.equals(action)) {
            BookFactory.getInstance().startPlay();
        }
        // 暂停
        else if (ACTION_PAUSE.equals(action)) {
            BookFactory.getInstance().stopPlay(true);
        }
        // 关闭通知
        else if (ACTION_CLOSE.equals(action)) {
            NotifyPlayHandler.getInstance().cancelPlay();
        }
    }
}